home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
singplay.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
5KB
|
156 lines
/* single playfield example v1.0 */
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
#include <exec/types.h>
#include <graphics/gfx.h>
#include <hardware/dmabits.h>
#include <hardware/custom.h>
#include <graphics/gfxmacros.h>
#include <graphics/rastport.h>
#include <graphics/view.h>
#include <exec/exec.h>
#define DEPTH 2
#define WIDTH 320
#define HEIGHT 200
#define NOT_ENOUGH_MEMORY -1000
#define FOREVER for(;;)
/* construct a simple display */
struct View v;
struct ViewPort vp;
struct ColorMap *cm; /* pointer to colormap structure, dynamic alloc */
struct RasInfo ri;
struct BitMap b;
struct RastPort rp;
short i,j,k,n;
struct ColorMap *GetColorMap();
struct GfxBase *GfxBase;
SHORT boxoffsets[] = { 802, 2010, 3218 };
USHORT colortable[] = { 0x000, 0xf00, 0x0f0, 0x00f };
/* black, red, green, blue */
UBYTE *displaymem;
UWORD *colorpalette;
main()
{
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
if (GfxBase == NULL) exit(1);
/* initialize view */
InitView(&v);
/* link view into viewport */
v.ViewPort = &vp;
/* init view port */
InitVPort(&vp);
/* now specify critical characteristics */
vp.DWidth = WIDTH;
vp.DHeight = HEIGHT;
vp.RasInfo = &ri;
/* init bit map (for rasinfo and rastport) */
InitBitMap(&b,DEPTH,WIDTH,HEIGHT);
/* (init RasInfo) */
ri.BitMap = &b;
ri.RxOffset = 0; /* align upper left corners of display
* with upper left corner of drawing area */
ri.RyOffset = 0;
ri.Next = NULL;
/* (init color table) */
cm = GetColorMap(4); /* 4 entries, since only 2 planes deep */
colorpalette = cm->ColorTable;
for(i=0; i<4; i++)
*colorpalette++ = colortable[i];
/* copy my colors into this data structure */
vp.ColorMap = cm; /* link it with the viewport */
/* allocate space for bitmap */
for(i=0; i<DEPTH; i++)
{
b.Planes[i] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
if(b.Planes[i] == NULL) exit(NOT_ENOUGH_MEMORY);
}
MakeVPort( &v, &vp ); /* construct copper instr (prelim) list */
MrgCop( &v ); /* merge prelim lists together into a real
* copper list in the view structure. */
for(i=0; i<2; i++)
{
displaymem = (UBYTE *)b.Planes[i];
for(j=0; j<RASSIZE(WIDTH,HEIGHT); j++)
*displaymem++ = 0;
/* zeros to all bytes of the display area */ }
LoadView(&v);
/* now fill some boxes so that user can see something */
/* always draw into both planes to assure true colors */
for(n=1; n<4; n++) /* three boxes */
{
for(k=0; k<2; k++)
{
displaymem = b.Planes[k] + boxoffsets[n-1];
DrawFilledBox(n,k);
/* boxes will be in red, green and blue */
}
}
FOREVER
; /* do nothing till user resets machine */
FreeMemory(); /* discussion purposes only, user has no
* way here to get past "FOREVER" in this
* simple program. FreeMemory is discussed
* in section below... Exiting Gracefully */
} /* end of main() */
DrawFilledBox(fillcolor,plane)
SHORT fillcolor,plane;
{
UBYTE value;
for(j=0; j<100; j++)
{
if((fillcolor & (1 << plane)) != 0)
value = 0xff;
else
value = 0;
for(i=0; i<20; i++)
{
*displaymem++ = value;
}
displaymem += (b.BytesPerRow - 20);
}
return;
}
FreeMemory()
{ /* return user and system-allocated memory to sys manager */
for(i=0; i<DEPTH; i++) /* free the drawing area */
FreeRaster(b.Planes[i],WIDTH,HEIGHT);
FreeColorMap(cm); /* free the color map */
/* free dynamically created structures */
FreeVPortCopLists(&vp);
FreeCprList(&v.LOFCprList);
return;
}